package logic

import (
	"context"
	"gorm.io/gorm"
	"qimao-fiction/model"

	"qimao-fiction/novelrpc/internal/svc"
	"qimao-fiction/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelUpdateLogic {
	return &NovelUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NovelUpdateLogic) NovelUpdate(in *novelrpc.NovelUpdateRequest) (*novelrpc.NovelUpdateResponse, error) {
	// todo: add your logic here and delete this line

	novel := model.Novel{
		Model: gorm.Model{
			ID: uint(in.NovelId),
		},
		Title:   in.Title,
		Content: in.Content,
		Img:     in.Img,
		UserId:  int(in.UserId),
	}
	model.DB.Debug().Updates(&novel)
	return &novelrpc.NovelUpdateResponse{
		NovelId: int64(novel.ID),
	}, nil
}
